#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}

cd $HOME
echo "Downloading..."
wget https://github.com/Itai-Nelken/Nativefier-WebApps/releases/download/v3.0/StackEdit-linux-armv7l.tar.xz || error 'Failed to Download!'
echo "extracting..."
tar -xf StackEdit-linux-armv7l.tar.xz || error "Failed to extract!"
echo "Renaming folder..."
mv ~/StackEdit-linux-armv7l ~/stackedit || error "Failed to rename folder!"
echo "Creating menu shortcut..."
echo "[Desktop Entry]
StartupNotify=true
Terminal=false
Type=Application
Name=StackEdit
Exec="$HOME/stackedit/StackEdit"
Path="$HOME/stackedit"
Icon="$HOME/pi-apps/apps/StackEdit/icon-64.png"
Categories=Development;IDE;" > ~/.local/share/applications/stackedit.desktop || error "Failed to create menu shortcut!"
rm -f StackEdit-linux-armv7l.tar.xz
